package com.wn.servlet.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yellow Docter
 * @date 2022 -07-05
 * @desc
 */
@WebServlet("/cookie01")
public class Cookie01Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        //浏览器查看cookie的url
        //chrome://settings/cookies/detail?site=localhost&search=cookie
        //创建cookie
        Cookie aa = new Cookie("aa", "11");
        Cookie bb = new Cookie("bb", "22");

        /**
         * cookie有生命周期
         * 负数 cookie 不持久化
         * 0   cookie 删除cookie
         * 正整数   cookie 的生命周期,单位秒
         */
        bb.setMaxAge(60 * 30);

        //服务器进行回写
        response.addCookie(aa);
        response.addCookie(bb);

    }
}
